/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rpt.lib.relatorio;

import net.sf.jasperreports.engine.JRDefaultStyleProvider;
import net.sf.jasperreports.engine.design.JRDesignBand;
import net.sf.jasperreports.engine.design.JRDesignExpression;
import net.sf.jasperreports.engine.design.JRDesignImage;
import net.sf.jasperreports.engine.design.JRDesignLine;
import net.sf.jasperreports.engine.design.JRDesignRectangle;
import net.sf.jasperreports.engine.design.JRDesignStaticText;
import net.sf.jasperreports.engine.design.JRDesignSubreport;
import net.sf.jasperreports.engine.design.JRDesignTextField;
import net.sf.jasperreports.engine.design.JasperDesign;

import net.sf.jasperreports.engine.type.LineDirectionEnum;
import net.sf.jasperreports.engine.type.PositionTypeEnum;
import net.sf.jasperreports.engine.type.ScaleImageEnum;

/**
 *
 * @author nulce-03
 */

public class CBandaRelatorio extends JRDesignBand {

    CEstiloRelatorio fEstilo;
    Object fJasperDesign = null;

    public CBandaRelatorio(
            final Object aJasperDesign, 
            final CEstiloRelatorio aEstilo) {
        super();
        fJasperDesign = aJasperDesign;
        fEstilo = aEstilo;
    }

    public void campoEstatico() {
        
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignExpression expressao(String aTexto, Class aClasse) {
        JRDesignExpression expression =
            new JRDesignExpression();
                expression.setValueClass(aClasse);
                expression.setText(aTexto);
        return expression;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
/*
    public JRDesignExpression expressao(Float aValor, Class aClasse, String aFormatoDecimal) {
        DecimalFormat df = new DecimalFormat(aFormatoDecimal);
        String vValorStr = df.format(aValor);
        JRDesignExpression expression = new JRDesignExpression();
        expression.setValueClass(aClasse);
        expression.setText(vValorStr);
        return expression;
    }
*/
    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignTextField campoTexto(
        String aExpressao,
        Class aClasse,
        String aPadrao,
        int aX, int aY, int aW, int aH,
        CEstiloRelatorio aEstiloRelatorio) {
        //
        JRDesignTextField tf = new JRDesignTextField();
        CEstiloRelatorio vEstilo = fEstilo;
        if (aEstiloRelatorio != null)
            vEstilo = aEstiloRelatorio;
        tf.setStyle(vEstilo);
        if (aPadrao != null) tf.setPattern(aPadrao);
        tf.setBlankWhenNull(true);
        tf.setX(aX);
        tf.setY(aY);
        tf.setWidth(aW);
        tf.setHeight(aH);
        tf.setExpression(expressao(aExpressao,aClasse));
        tf.setStretchWithOverflow(true);
        addElement(tf);
        return tf;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignSubreport subRelatorio(
        String aExpressao,
        Class aClasse,
        String aPadrao,
        int aX, int aY, int aW, int aH,
        CEstiloRelatorio aEstiloRelatorio) {
        //
        JRDesignSubreport sr = new JRDesignSubreport(null);
        CEstiloRelatorio vEstilo = fEstilo;
        if (aEstiloRelatorio != null)
            vEstilo = aEstiloRelatorio;
        sr.setStyle(vEstilo);
        sr.setX(aX);
        sr.setY(aY);
        sr.setWidth(aW);
        sr.setHeight(aH);
        sr.setExpression(expressao(aExpressao,aClasse));
        addElement(sr);
        return sr;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignTextField campoTextoBd(
        String aNomeCampo,
        Class aClasse,
        String aPadrao,
        int aX, int aY, int aW, int aH,
        CEstiloRelatorio aEstiloRelatorio) {
        //
        return campoTexto("$F{"+aNomeCampo+"}",aClasse,aPadrao,aX,aY,aW,aH,aEstiloRelatorio);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignTextField campoTextoNumericoBd(
        final String aNomeCampo,
        final String aFormatoDecimal,
        final Class aClasse,
        final String aPadrao,
        final int aX, final int aY, final int aW, final int aH,
        final CEstiloRelatorio aEstiloRelatorio) {
        //
        JRDesignTextField ct =
            campoTexto("$F{"+aNomeCampo+"}",aClasse,aPadrao,aX,aY,aW,aH,
            //aModo,
            //aAlinhamentoHorizontal,
            aEstiloRelatorio);
        ct.setPattern(aFormatoDecimal);
        return ct;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignStaticText textoEstatico(
        String aTexto,
        int aX, int aY, int aW, int aH,
        CEstiloRelatorio aEstilo) {
        //
        JRDesignStaticText st = new JRDesignStaticText();
        CEstiloRelatorio vEstilo = fEstilo;
        if (aEstilo != null) {
            vEstilo = aEstilo;
        }
        st.setStyle(vEstilo);
        st.setText(aTexto);
        st.setX(aX);
        st.setY(aY);
        st.setWidth(aW);
        st.setHeight(aH);
        addElement(st);
        return st;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
/*
    public JRDesignStaticText textoEstatico(
        String aTexto,
        int aX, int aY, int aW, int aH,
        CEstiloRelatorio aEstiloRelatorio) {
        //
        return
            textoEstatico(aTexto,aX,aY,aW,aH,
            //fModo,
            //fAlinhamentoHorizontal,
            aEstiloRelatorio);
    }
*/
    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignRectangle retangulo(
        int aX, int aY, int aW, int aH) {
        //
        JRDesignRectangle r = new JRDesignRectangle();
        r.setX(aX);
        r.setY(aY);
        r.setWidth(aW);
        r.setHeight(aH);
        addElement(r);
        return r;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignLine linha(
            final int aX,
            final int aY,
            final int aW,
            final int aH,
            final LineDirectionEnum aLineDirectionEnum) {
        //
        JRDesignLine dl = new JRDesignLine();
        dl.setX(aX);
        dl.setY(aY);
        dl.setWidth(aW);
        dl.setHeight(aH);
        dl.setDirection(aLineDirectionEnum);
        addElement(dl);
        return dl;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignLine linha(
            final int aX,
            final int aY,
            final int aW,
            final int aH) {
        //
        return linha(aX,aY,aW,aH,LineDirectionEnum.TOP_DOWN);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignLine linhaAcima(
        int aX, int aY, int aW, int aH) {
        //
        JRDesignLine l = new JRDesignLine();
        l.setX(aX);
        l.setWidth(aW);
        l.setHeight(aH);
        l.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_TOP);
        addElement(l);
        return l;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignLine linhaAbaixo(
        int aX, int aY, int aW, int aH) {
        //
        JRDesignLine l = new JRDesignLine();
        l.setX(aX);
        l.setWidth(aW);
        l.setHeight(aH);
        l.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_BOTTOM);
        addElement(l);
        return l;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public void traco() {
        
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignImage imagem(
        int aX, int aY, int aW, int aH,
        String aCaminhoImagem,
        ScaleImageEnum aScaleImageEnum) {
        //
        if (!(fJasperDesign instanceof JasperDesign)) return null;
        JRDesignImage imagem  = new JRDesignImage((JasperDesign)fJasperDesign);
        imagem.setX(aX);
        imagem.setY(aY);
        imagem.setWidth(aW);
        imagem.setHeight(aH);
        imagem.setScaleImage(aScaleImageEnum); // ScaleImageEnum.CLIP);
        imagem.setExpression(
            expressao(aCaminhoImagem,java.lang.String.class));
        addElement(imagem);
        JRDefaultStyleProvider x = null;
        return imagem;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
/*
    public JRCrosstab crosstab(
        int aX, int aY, int aW, int aH) {
        //
        JRCrosstab ct = new JRCrosstab();
        ct.setX(aX);
        ct.setY(aY);
        ct.setWidth(aW);
        ct.setHeight(aH);
        addElement(ct);
        return ct;
    }
*/
}
